<?php
/* @var $this CategroryController */
/* @var $model Categrory */
/* @var $form CActiveForm */
?>
<?php
/* @var $this PostsController */
/* @var $model Posts */
/* @var $form CActiveForm */
?>
<div class="content">
    <div class="grid">
        <div class="grid-title">
            <div class="pull-left">Tạo danh mục mới</div>
            <div class="pull-right"></div>
            <div class="clear"></div>
        </div>

        <div class="grid-content">
            <?php
            $form = $this->beginWidget('CActiveForm', array(
                'id' => 'posts-form',
                'enableAjaxValidation' => false,
            ));
            ?>
            <div class="formRow">
                <?php echo $form->labelEx($model, 'cat_name'); ?>
                <div class="formRight">
                    <?php echo $form->textField($model, 'cat_name', array('size' => 60, 'maxlength' => 500)); ?>
                </div>
            </div>
            <div class="formRow">
                <?php echo $form->labelEx($model, 'slug'); ?>
                <div class="formRight">
                    <?php echo $form->textField($model, 'slug'); ?>
                </div>
            </div>

            <div class="formRow">
                <?php echo CHtml::label('Thư mục cha', 'parent_label'); ?>
                <div class="formRight">
                    <?php echo CHtml::dropDownList('cat_parent', '', Categrory::getCatlist()); ?>
                </div>
            </div>
            <div class="formRow">
                <?php echo $form->labelEx($model, 'order_by'); ?>
                <div class="formRight">
                    <?php echo $form->textField($model, 'order_by'); ?>
                </div>
            </div>
            <div class="formRow">
                <?php echo CHtml::submitButton($model->isNewRecord ? 'Lưu' : 'Cập nhật'); ?>
            </div>

            <?php $this->endWidget(); ?>
        </div>
    </div> 
</div> <!-- end class content -->
<script type="text/javascript">
    function convertToSlug(Text)
    {
        // Xử lý ký tự Unicode
        in_chrs = 'áàảãạăắặằẳẵâấầẩẫậđéèẻẽẹêếềểễệóòỏõọôốồổỗộơớờởỡợúùủũụưứừửữựýỳỷỹỵÁÀẢÃẠĂẮẶẰẲẴÂẤẦẨẪẬĐÉÈẺẼẸÊẾỀỂỄỆÍÌỈĨỊíìỉĩịÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢÚÙỦŨỤƯỨỪỬỮỰÝỲỶỸỴ',
                out_chrs = 'aaaaaaaaaaaaaaaaadeeeeeeeeeeeooooooooooooooooouuuuuuuuuuuyyyyyAAAAAAAAAAAAAAAAADEEEEEEEEEEEIIIIIiiiiiOOOOOOOOOOOOOOOOOOUUUUUUUUUUUUYYYYY'
        transl = {};

        eval('var chars_rgx = /[' + in_chrs + ']/g');
        for (var i = 0; i < in_chrs.length; i++)
        {
            transl[in_chrs.charAt(i)] = out_chrs.charAt(i);
        }
        Text = Text.replace(chars_rgx, function(match) {
            return transl[match];
        });

        Text = Text
                .toLowerCase()
                .replace(/ /g, '-')
                .replace(/[^\w-]+/g, '')
                .replace(/--/g, '-');

        // Bỏ đi các ký tự đặc biệt
        return Text;
    }

    $('#Categrory_cat_name').keyup(function() {
        title = $('#Categrory_cat_name').val();
        $('#Categrory_slug').val(convertToSlug(title));
    });
</script>

